from flask import g
from flask_restful import Resource
from sqlalchemy.orm import load_only

from models.user import User
from utils.decorators import login_required

from cache.user import UserCache


class CurrentUserResource(Resource):
    """个人中心-当前用户"""
    method_decorators = {'get': [login_required]}

    def get(self):
        # 获取用户id
        userid = g.userid

        # 查询用户数据
        user_cache = UserCache(userid).get()
        if user_cache:
            return user_cache
        else:
            return {'message': "Invalid User", 'data': None}, 400